new Vue({
    el: '#app',
    data() {
        return {
            isflageIOX: true,
            searchWidth: 24,
            historytotal: 0,
            loading: false,
            isSearchFocused: false,
            finished: false,
            historyCurrent: 1,
            searchParams: "",
            clipboard: {
                content: "",
            },
            pptList: [
                // {id:"1",meetingName:"测试数据",createTime:'2024-12-19'}
            ],
            showSearch: false,
            shareShow: false,
            shareTypeList: [{id:"1", type: 1, title:'会议录音', logo:'../images/meetingFour/hyly.png'},
                {id:"2", type: 2, title:'会议记录', logo:'../images/meetingFour/hyjl.png'},
                // {id:"3", type: 3, title:'会议摘要', logo:'../images/meetingFour/hyzyw.png'},
                // {id:"4", type: 4, title:'会议摘要', logo:'../images/meetingFour/hyzyp.png'},
            ],
            selShareType: 1,
            selItem: {}
        }
    },
    watch: {

    },
    created() {
        const _this = this
        let jsApiList = []
        $.getScript("../../../js/jweixin-sgccigw-1.0.0.js" /*"js/jweixin-1.0.0.js"*/, function () {
            'use strict';
            wx.ready(function () {
                wx.onHistoryBack(() => {
                    _this.home()
                    return false
                })
            });
            jsApiList = [
                'previewFile',
                'onHistoryBack',
            ];
            wx.config({
                beta: true, // 调用wx.invoke形式的接口值时，该值必须为true。
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                appId: corpid,
                timestamp: '1626832073',
                nonceStr: nonceStr,
                signature: signature,
                jsApiList: jsApiList
            });
        });
    },
    mounted() {
        this.compatibleInput()
        this.queryList()
    },
    methods: {
        getStatusImg(item) {
            if(2 == item.dataType) {
                return '../images/meetingFour/meeting_status_over.png'
            }else {
                return '../images/meetingFour/meeting_loading.png'
            }
        },
        showShare(item) {
            if(2 == item.dataType) {
                return true
            }else {
                return false
            }
        },
        handleShareTypeSelect(item) {
            this.selShareType = item.type
        },
        //分享
        openShare(item){
            if(!item.id) {
                mui.toast('未生成文件，请生成后再试', {
                    duration: 1000,
                    type: 'div'
                })
                return
            }
            if(1 == item.type) {
                this.shareIgw({id: item.id})
            }else {
                this.selItem = item
                this.shareShow = true;
            }
        },
        shareConfirm(){
            console.log(this.selShareType)
            let fileId = null
            if(1 == this.selShareType) {
                fileId = this.selItem.voiceAttach
            }else if(2 == this.selShareType) {
                fileId = this.selItem.id
            }
            // else if(3 == this.selShareType) {
            //     fileId = this.selItem.wordId
            // }else if(4 == this.selShareType) {
            //     fileId = this.selItem.pdfId
            // }
            if(!fileId) {
                mui.toast('文件不存在', {
                    duration: 1000,
                    type: 'div'
                })
            }
            this.shareIgw({id: fileId})
        },
        //分享
        shareIgw(item) {
            if(!item.id) {
                return
            }
            shareIgw({
                sceneNo: '111',
                shareType: 1,
                attchId: item.id
            })
         },
        preview(item) {
            // if(1 == item.type) {
            //     myPreviewFile(item)
            // }else {
            //     sessionStorage.setItem('meeting_id', item.meetingId)
            //     let meeting_name = item.name.substr(0, item.name.length-5)
            //     sessionStorage.setItem('meeting_name', meeting_name)
            //     sessionStorage.setItem('meeting_voiceDuration', item.voiceDuration)
            //     sessionStorage.setItem('meeting_createTime', item.createTime)
            //     $(location).attr("href", "./meetingVoice.html");
            // }
            // if(item.id) {
            //     myPreviewFile(item)
            // }else {
            //     sessionStorage.setItem('meeting_id', item.meetingId)
            //     sessionStorage.setItem('meeting_type', item.meetingType)
            //     $(location).attr("href", "./realtime.html");
            // }

            if(1 == item.dataType) {

                if(1 != item.transStatus) {
                    //未完成话者分离图标为0
                    if(0 == item.meetingType) {
                        sessionStorage.setItem('current_meeting_step', 1)
                    }else {
                        sessionStorage.setItem('current_meeting_step', 2)
                    }
                    sessionStorage.setItem('meeting_id', item.meetingId)
                    sessionStorage.setItem('meeting_type', item.meetingType)
                    $(location).attr("href", "./realtime.html");
                }else if(1 == item.transStatus && 1 != item.checkStatus) {
                    sessionStorage.setItem('current_meeting_step', 2)
                    sessionStorage.setItem('meeting_id', item.meetingId)
                    sessionStorage.setItem('meeting_type', item.meetingType)
                    $(location).attr("href", "./realtime.html");
                }else if(1 == item.checkStatus && !item.id) {
                    //完成纠错未完成生成内容图标是2
                    sessionStorage.setItem('current_meeting_step', 3)
                    sessionStorage.setItem('meeting_id', item.meetingId)
                    sessionStorage.setItem('meeting_type', item.meetingType)
                    $(location).attr("href", "./realtime.html");
                }else if(item.id) {
                    //完成纠错且生成语音文档,开始填写表单
                    sessionStorage.setItem('current_meeting_step', 4)
                    sessionStorage.setItem('meeting_id', item.meetingId)
                    sessionStorage.setItem('meeting_type', item.meetingType)
                    $(location).attr("href", "./realtime.html");
                }
            }else if(2 == item.dataType){
                if(1 == item.type) {
                    myPreviewFile(item)
                }else {
                    sessionStorage.setItem('meeting_id', item.meetingId)
                    let meeting_name = item.name.substr(0, item.name.length-5)
                    sessionStorage.setItem('meeting_name', meeting_name)
                    sessionStorage.setItem('meeting_voiceDuration', item.voiceDuration)
                    sessionStorage.setItem('meeting_createTime', item.createTime)
                    $(location).attr("href", "./meetingVoice.html");
                }
            }

            // const userId = sessionStorage.getItem("userId");
            // let param = {
            //     "userId": userId,
            //     "id": item.wordId,
            //     "timestamp": new Date().getTime() + "",
            // };
            // let AuthenticationSession = sessionStorage.getItem("Authentication");
            // data = JSON.stringify(param)
            // let sign = sm3(data);
            // $.ajax({
            //     url: localUrlLink + iscp_port + "/tjAiAssistant/common/getAttachInfo",
            //     type: "post",
            //     async: false, //是否同步，false表示同步请求
            //     dataType: "json",
            //     data: data,
            //     headers: {
            //         "Content-Type": "application/json;charset=UTF-8",
            //         Authentication: AuthenticationSession,
            //         sign: sign
            //     },
            //     success: (res, txt, xhr) => {
            //         if (sm3(res.resultValueStr) == xhr.getResponseHeader("sign")) {
            //             let Authentication = xhr.getResponseHeader("Authentication")
            //             if (res.code == 200) {
            //                 if (Authentication) {
            //                     sessionStorage.setItem("Authentication", Authentication);
            //                 }
            //                 myPreviewFile(res.resultValue)
            //             } else {
            //                 mui.toast('请稍后再试', {
            //                     duration: 1000,
            //                     type: 'div'
            //                 })
            //             }
            //         }
            //     },
            //     error: (e) => {
            //         $(".curtain").css("display", "none");
            //         mui.toast('请稍后再试', {
            //             duration: 1000,
            //             type: 'div'
            //         })
            //     },
            // });
            
        },
        //显示搜索框或者直接搜索
        searchShow(){
            this.showSearch = true;
            this.isSearchFocused = true;
            this.shareShow = false
            return false;
        },
        queryList() {
            this.finished = false;
            const userId = sessionStorage.getItem("userId");
            let param = {
                "userId": userId,
                "keyWord": this.searchParams,
                // "dataType": 1,
                "current": this.historyCurrent,
                "size": 10,
                "timestamp": new Date().getTime() + "",
            };
            let AuthenticationSession = sessionStorage.getItem("Authentication");
            data = JSON.stringify(param)
            let sign = sm3(data);
            $.ajax({
                url: localUrlLink + iscp_port + "/tjAiAssistant/meetingFour/queryList",
                type: "post",
                async: false, //是否同步，false表示同步请求
                dataType: "json",
                data: data,
                headers: {
                    "Content-Type": "application/json;charset=UTF-8",
                    Authentication: AuthenticationSession,
                    sign: sign
                },
                success: (res, txt, xhr) => {
                    if (sm3(res.resultValueStr) == xhr.getResponseHeader("sign")) {
                        let Authentication = xhr.getResponseHeader("Authentication")
                        if (res.code == 200) {
                            if (Authentication) {
                                sessionStorage.setItem("Authentication", Authentication);
                            }
                            // this.pptList = []
                            this.historytotal = res.resultValue.total
                            res.resultValue.list.forEach((item) => {
                                this.pptList.push(item)
                            })
                            if (this.historytotal == 0) {
                                this.finished = true;
                            }
                            if (res.resultValue.list.length < 10) {
                                this.finished = true;
                            }
                            this.loading = false;
                            // if (this.pptList.length >= this.historytotal) {
                            //     this.finished = true;
                            // }
                            this.cleanData()
                        } else {
                            mui.toast('请稍后再试', {
                                duration: 1000,
                                type: 'div'
                            })
                        }
                    }
                },
                error: (e) => {
                    $(".curtain").css("display", "none");
                    mui.toast('请稍后再试', {
                        duration: 1000,
                        type: 'div'
                    })
                },
            });
        },
        delConfirm(item) {
            $(".curtain").css("display", "block");
            const userId = sessionStorage.getItem("userId");
            let param = {
                "userId": userId,
                "type": item.type,
                "id": item.meetingId,
                "timestamp": new Date().getTime() + "",
            };
            let AuthenticationSession = sessionStorage.getItem("Authentication");
            data = JSON.stringify(param)
            let sign = sm3(data);
            $.ajax({
                url: localUrlLink + iscp_port + "/tjAiAssistant/meetingFour/deleteByType",
                type: "post",
                async: false, //是否同步，false表示同步请求
                dataType: "json",
                data: data,
                headers: {
                    "Content-Type": "application/json;charset=UTF-8",
                    Authentication: AuthenticationSession,
                    sign: sign
                },
                success: (res, txt, xhr) => {
                    $(".curtain").css("display", "none");
                    if (res.code == 200) {
                        this.pptList = []
                        this.historyCurrent = 1
                        this.queryList()
                    } else {
                        mui.toast('请稍后再试', {
                            duration: 1000,
                            type: 'div'
                        })
                    }
                },
                error: (e) => {
                    $(".curtain").css("display", "none");
                    mui.toast('请稍后再试', {
                        duration: 1000,
                        type: 'div'
                    })
                },
            });
        },
        topptView(type) {
            sessionStorage.setItem('meeting_type', type)
            $(location).attr("href", "./realtime.html");

            // this.functionBtn()
        },
        // 选择文件
        functionBtn(num) {
            if (this.isflageIOX == true) {
              wx.chooseImage({
                count: 1,
                sizeType: ["compressed"],
                sourceType: ["album", "camera"],
                quality: 0.3,
                success: (res) => {
                  var localIds = res.localIds[0];
                  console.log(res)
                  let slocalResPath = "";
                  wx.invoke(
                    "getLocalResPath", {
                      localId: localIds,
                    },
                    (res) => {
                      slocalResPath = res.localResPath;
                      wx.invoke(
                        "ext_FileManager_Information", {
                          data: {
                            path: slocalResPath,
                          },
                        },
                        (res) => {
                          console.log("ext_FileManager_Information", res)
                        }
                      );
                    }
                  );
                },
              });
            } else {
              wx.chooseImage({
                count: 1,
                sizeType: ["compressed"],
                sourceType: ["album", "camera"],
                quality: 0.1,
                success: (res) => {
                  var localIds = res.localIds[0];
                  console.log(res)
                  let slocalResPath = "";
                  wx.invoke(
                    "getLocalResPath", {
                      localId: localIds,
                    },
                    (res) => {
                      slocalResPath = res.localResPath;
                      wx.invoke(
                        "ext_FileManager_Information", {
                          data: {
                            path: slocalResPath,
                          },
                        },
                        (res) => {
                            console.log("ext_FileManager_Information", res)
                        }
                      );
                    }
                  );
                },
              });
            }
          },
        handleFocus() {
            this.isSearchFocused = true;
            this.searchWidth = 20;
            console.log("isSearchFocused",this.isSearchFocused);
        },
        handleBlur() {
            this.isSearchFocused = false;
            this.searchWidth = 24;
            console.log("isSearchFocused",this.isSearchFocused);
        },
        onSearch() {
            this.pptList = [];
            this.historyCurrent = 1;
            this.queryList();
            // this.searchParams = '';
        },
        onCancel() {
            this.searchParams = '';
            this.showSearch = false;
            this.isSearchFocused = false;
            this.searchWidth = 24;
            this.queryList();
        },
        cleanData() {
            this.searchParams = '';
            this.showSearch = false;
            this.isSearchFocused = false;
            this.searchWidth = 24;
            // this.queryList();
        },
        onLoad() {
            if (!this.historyCurrent === 0) {
                this.finished = this.pptList.length >= this.historytotal;

            }
            if (!this.finished) {
                this.historyCurrent = this.historyCurrent + 1;
                this.queryList();
            }
        },
        //复制按钮
        copy() {
            let text1 = this.clipboard.content;
            var clipboard = new Clipboard(".tag-read", {
                // 通过target指定要复印的节点
                text: function () {
                    return text1;
                },
            });
            clipboard.on("success", (e) => {
                addOperator(2, 11, "复制文本", 1, 1, "复制成功");
                mui.toast("复制成功", {
                    duration: "long",
                    type: "div"
                });
            });
            clipboard.on("error", (e) => {
                addOperator(2, 11, "复制文本", 1, 0, "复制失败");
            });
        },
        // 判断安卓还是ios
        compatibleInput() {
            //获取浏览器的userAgent,并转化为小写
            var ua = navigator.userAgent.toLowerCase();
            //判断是否是苹果手机，是则是true
            var isIos = ua.indexOf("iphone") != -1 || ua.indexOf("ipad") != -1;
            if (isIos) {
                this.isflageIOX = true;
            } else {
                this.isflageIOX = false;
            }
        },
        home() {
            $(location).attr("href", "../../Home.html");
        },
        createSgin(data) {
            let hashData = sm3(data);
            let hashData_last = sm3(hashData);
            hashData_last = hashData_last.substr(0, 5);
            hashData += hashData_last;
            let sign = hashData;
            return sign;
        },
    }
})